#!/bin/bash

# Set maintenance flag
MFLAG=/etc/columnstore/maintenance

exec {lock_fd}>/var/lock/cmapi-restart || exit 1
flock -n "$lock_fd" || { echo 'ERROR: This script is already running.' >&2; exit 1; }
touch $MFLAG
monit unmonitor all
cmapi-stop
cmapi-start
monit monitor all
rm -f $MFLAG
flock -u "$lock_fd"
